package de.justphil.tcg.tcgserver.game.mechanics.property;

import java.util.List;

import de.justphil.tcg.tcgserver.game.mechanics.event.Event;
import de.justphil.tcg.tcgserver.game.mechanics.game.Attack;
import de.justphil.tcg.tcgserver.game.mechanics.game.Game;
import de.justphil.tcg.tcgserver.game.mechanics.monster.Monster;
import de.justphil.tcg.tcgserver.game.mechanics.monster.MonsterList;

public abstract class OnHitProvider extends Property {

	public OnHitProvider(Game game) {

		super(game);
	}

	@Override
	protected MonsterList handleEvent(Event event) {

		switch (event.getType()) {
		case Event.EVENT_MONSTER_HIT:
			
			MonsterList monsters = new MonsterList();
			monsters.add(handleMonsterHit((Attack)event.getData()));
			return monsters;

		default:
			break;
		}
		return null;
	}
	
	private Monster handleMonsterHit(Attack attack){
		
		if (attack.getAttacker().equals(getMonster())) {

			if (isStackable() || !attack.getTarget().getProperties().contains(this)) {
				
				provideProperty(attack.getTarget(), getProvidedProperty());
				return attack.getTarget();
			}
		}
		return null;
	}

	protected abstract int getProvidedProperty();

	@Override
	protected List<Integer> getListeningEventTypes() {

		List<Integer> types = super.getListeningEventTypes();
		types.add(Event.EVENT_MONSTER_HIT);

		return types;
	}

}
